package com.yuanss.smart.fdemo.aspect;

import com.yuanss.smart.framework.annotation.Aspect;
import com.yuanss.smart.framework.annotation.Controller;
import com.yuanss.smart.framework.proxy.AspectProxy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Method;

/**
 * @Description 拦截控制器类
 * @Date 2024/11/18 下午8:12
 * @Created by 菜到不敢run
 */
@Aspect(Controller.class)
public class ControllerAspect extends AspectProxy {

    private static final Logger LOGGER = LoggerFactory.getLogger(ControllerAspect.class);

    private long begin;

    @Override
    public void before(Class<?> cls, Method method, Object[] params) throws Throwable {
        LOGGER.info("begin {}.{}", cls.getName(), method.getName());
        begin = System.currentTimeMillis();
        super.before(cls, method, params);
    }

    @Override
    public void after(Class<?> cls, Method method, Object[] params, Object result) throws Throwable {
        super.after(cls, method, params, result);
        LOGGER.info("耗时：{}", System.currentTimeMillis() - begin);
    }
}
